<template>
	<view class="top-bar-box" v-if="isBar">
		<view class="top-bar-space" v-if="space"></view>
		<view class="top-bar-app fboxRow Ycenter" @click="openApp" id="btn">
			<view class="flex1 font30 fboxRow Ycenter">
				<image class="logo" src="https://ebc-prod.cdn.benwunet.com/uni-static/bw-logo.png"
					mode="aspectFill"></image> 本无名片
			</view>
			<view class="btn font28 fboxRow Ycenter Xcenter">打开APP</view>
		</view>
	</view>
</template>

<script>
	import {
		getAndroidVersion
	} from '@/api/index.js';
	
	import {base64decode, base64encode} from '@/static/js/Base64.js';
	import { openAppULink, openAppULinkNew } from '@/static/js/common.js';
	export default {
		name: 'topBar',
		components: {},
		props: {
			show: {
				type: Boolean,
				default: true
			},
			space: {
				type: Boolean,
				default: true
			},
			linkData: {
				type: Object,
				default: () => {
					return {}
				}
			},
			linkId: {
				type: String,
				default: 'usr103rs12t9nk1c'
			},
			isOpeninstall: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				urlAndroid: '',
				isBar: false,
			};
		},
		computed: {
			_show: {
				get() {
					return this.show
				},
				set(val) {
					this.$emit('update:show', val)
				}
			},
			_linkData:{
				get() {
					return this.linkData
				},
				set(val) {
					this.$emit('update:linkData', val)
				}
			}
		},
		created() {
			// #ifdef H5
			this.isApp()
			this.isBar = true
			// #endif
		},
		mounted() {
			// #ifdef H5
			const script = window.document.createElement("script");
			script.type = "text/javascript";
			script.src = "https://g.alicdn.com/jssdk/u-link/index.min.js";
			document.getElementsByTagName("head")[0].appendChild(script);
			// #endif
		},
		methods: {
			isApp() {
				getAndroidVersion().then(res => {
					this.urlAndroid = res.data.updateAddress
				})
			},
			openApp() {
				console.log(11111)
				const {bw_link, bw_user_temp} = getApp().getBWData(['bw_link', 'bw_user_temp'])
				const href = window.location.href
				const obj = {
					...this._linkData,
					sharerId: bw_link.sharerId,
					href: href // .substr(0, href.indexOf("?"))
				}
				// openAppULink(this.linkId, obj, this.urlAndroid)
				const openFun = this.isOpeninstall ? openAppULinkNew : openAppULink;
				openFun(this.linkId, obj, this.updateAddress);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.top-bar-space {
		width: 750rpx;
		height: 80rpx;
	}

	.top-bar-app {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 999;
		padding: 0 0 0 30rpx;
		width: 750rpx;
		height: 80rpx;
		background: #FFEBC9;
	}

	.logo {
		margin-right: 10rpx;
		width: 42rpx;
		height: 42rpx;
		background: #121575;
		border-radius: 50%;
		overflow: hidden;
	}

	.btn {
		// width: 120rpx;
		padding: 0 30rpx;
		height: 80rpx;
		// height: 48rpx;
		background: #C5130A;
		// border-radius: 4rpx;
		color: #FFD161
	}
</style>